 <template>
  <div>
    <div class="top">
      <span class="fh"><van-icon name="arrow-left" @click="fh" /></span>
      <span class="zc">手机快速注册</span>
      <span class="dl" @click="dl">登录</span>
    </div>
    <div class="mainCenter">
      <van-form @submit="onSubmit(username)">
        <van-field
          v-model="username"
          name="手机号"
          label="请输入手机号"
          placeholder="请输入11位手机号"
          :rules="[{ required: true, message: '请填写手机号' }]"
          class="yhm"
          @input="yanzheng"
        />
        <div style="margin: 16px">
          <van-button
            round
            block
            type="info"
            native-type="submit"
            :disabled="disabled_flag"
            >下一步</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { Toast } from "vant";
export default {
  name: "Register",
  data() {
    return {
      username: "",
      disabled_flag: true,
    };
  },
  methods: {
    yanzheng() {
      let reg = new RegExp(
        /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
      );
      if (reg.test(this.username)) {
        this.disabled_flag = false;
      } else {
        this.disabled_flag = true;
      }
    },
    onSubmit(values) {
      // console.log("submit", values);
      this.$service({
        method:"post",
          url: "/api/user/docheckphone",
          data: { tel: this.username },
        })
        .then((res) => {
          console.log(res);
          if (res.data.code == "10005") {
            Toast("该用户已注册");
            return;
          }
          localStorage.setItem("userphone", JSON.stringify(values));
          this.$router.push({ path: "/PhoneTest" });
        });
    },
    fh() {
      this.$router.push("/Login");
    },
    dl() {
      this.$router.push("/Login");
    },
  },
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  list-style: none;
  text-decoration: none;
}
.top {
  height: 3rem;
  text-align: center;
  line-height: 3rem;
  border-bottom: 2px solid gray;
  position: relative;
}
.fh {
  position: absolute;
  font-size: 20px;
  left: 1rem;
}
.yhm {
  height: 4rem;
  line-height: 4rem;
  margin-bottom: 1rem;
}
.dl {
  position: absolute;
  right: 0.5rem;
}
</style>